package shiqi.service.user.impl;

import org.springframework.stereotype.Service;
import shiqi.convert.ConvertUtil;
import shiqi.db.Db;
import shiqi.constants.DbConstants;
import shiqi.db.DbFactory;
import shiqi.model.User;
import shiqi.service.user.UserService;
import shiqi.vo.UserVo;

import static shiqi.constants.DbEnum.MAPUSERDATASOURCE;

/**
 * @program: ascend
 * @description: 用户服务实现类2
 * @author: shiqi
 * @create: 2022-03-17 17:10
 **/
@Service("mapUserService")
public class MapUserServiceImpl implements UserService {

    @Override
    public boolean login(UserVo vo) throws IllegalAccessException {
        Db<User, Long> userDb = DbFactory.getReallyDb(MAPUSERDATASOURCE);
        User user = new User();
        ConvertUtil.convert(user, vo);
        System.out.println(user);
        User result = userDb.search(user);
        if (result != null) {
            return true;
        }
        return false;
    }

    @Override
    public User searchById(Long id) {
        Db<User, Long> userDb = DbFactory.getReallyDb(MAPUSERDATASOURCE);
        return userDb.searchById(id);
    }
}
